package com.wzq.solution;

import java.util.ArrayList;
import java.util.List;

class Solution77 {
    
    List<List<Integer>> rst = new ArrayList<List<Integer>>();

    List<Integer> list= new ArrayList<Integer>();
    int n,k;
    public List<List<Integer>> combine(int n, int k) {
        this.n=n;
        this.k=k;
        foo(0,1);

        return rst;
    }
    
    private void foo(int cnt,int start){
        if(cnt == k){
            rst.add(new ArrayList<Integer>(list));
            System.out.println(list);
            return;
        }

        for(int i=start;i<=n-k+cnt+1;i++){
            if(list.size()<=cnt){
                list.add(i);
            }else{
                list.set(cnt,i);
            }
            foo(cnt+1,i+1);
        }
    }


    public static void main(String[] args) {
        new Solution77().combine(4,2);
    }
}